#include <stdio.h>
typedef struct
{
	char stu[100];
	int score;
	int english;
} STUDENT;
void exchange(STUDENT* p1,STUDENT* p2)
{
	STUDENT temp=*p1;
	*p1=*p2;
	*p2=temp;
}
int cmp(char* p1,char* p2)
{
	int number1;
	int number2;
	sscanf(p1,"XD%d",&number1);
	sscanf(p2,"XD%d",&number2);
	return number1-number2;
}
int main()
{
	int m,n;
	scanf("%d %d",&m,&n);
	STUDENT students[m];
	for(int i=0;i<m;i++)
	{
		scanf("%s %d %d",students[i].stu,&students[i].score,&students[i].english);
	}
	for(int i=0;i<m-1;i++)
	{
		for(int s=0;s<m-i-1;s++)
		{
			if(students[s].score<students[s+1].score||((students[s].score==students[s+1].score)&&(students[s].english<students[s+1].english))||((students[s].score==students[s+1].score)&&(students[s].english==students[s+1].english)&&(cmp(students[s].stu,students[s+1].stu))>0))
			{
				exchange(&students[s],&students[s+1]);
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		printf("%s %d %d\n",students[i].stu,students[i].score,students[i].english);
	}
	return 0;
	
}
